﻿// =================================================================== 
// 数据访问层(GDIT.DAL)
//====================================================================
// 文件：DVideoInformationArticle.cs
// 项目名称：学院网站
// 创建时间：2012-08-08
// 负责人：ChenZhiGang
//引用DevExpress.Data.Filtering，DevExpress.Xpo程序集
// 程序集介绍：视频资讯文章信息数据访问层
// ===================================================================
using GDIT.Model;
using DevExpress.Data.Filtering;
using DevExpress.Xpo;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using GDIT.Pattern;
using System.Data;

namespace GDIT.DAL
{
    public class DVideoInformationArticle : IVideoInformationArticle
    {

        private XpoHelper.Test<Mtb_VideoInformationArticle> userOperation = null;

        /// <summary>
        /// 管理员展示页面
        /// </summary>
        /// <returns></returns>
        public XPCollection SelectAllVideoyAdmin()
        {
            userOperation = new XpoHelper.Test<Mtb_VideoInformationArticle>();
            return userOperation.Operation();
        }

        /// <summary>
        /// 新增加一篇视频资讯
        /// </summary>
        /// <param name="bulletin">需要增加的视频资讯对象</param>
        /// <returns>1：新增成功  0：新增失败</returns>
        public int InsertVideoInformationArticle(Mtb_VideoInformationArticle bulletin)
        {
            return XpoHelper.SaveAdded(bulletin);
        }

        /// <summary>
        /// 删除一篇视频资讯
        /// </summary>
        /// <param name="bulletin">需要删除的视频资讯对象</param>
        /// <returns>1：新增成功  0：新增失败</returns>
        public int DeleteVideoInformationArticle(int id)
        {
            userOperation = new XpoHelper.Test<Mtb_VideoInformationArticle>();
            return userOperation.Delete(id);
        }

        /// <summary>
        /// 更新一篇视频资讯
        /// </summary>
        /// <param name="bulletin">需要更新的视频资讯的对象</param>
        /// <returns>1：新增成功  0：新增失败</returns>
        public int UpdateVideoInformationArticle(Mtb_VideoInformationArticle bulletin)
        {
            userOperation = new XpoHelper.Test<Mtb_VideoInformationArticle>();
            XPCollection xp = userOperation.Operation("OID", bulletin.OID);
            foreach (Mtb_BulletinArticle b in xp)
            {
                b.Title = bulletin.VideoName;
                b.Contents = bulletin.LinkAddress;
                b.Important = bulletin.Important;
                b.Top = bulletin.Top;
                return XpoHelper.SaveModified(b);
            }
            return 0;
        }

        /// <summary>
        /// 查询所有非置顶，重点的公告列表
        /// </summary>
        /// <returns>返回所有的视频资讯列表</returns>
        public XPCollection SelectAllVideoInformationArticle()
        {
            GroupOperator criteria = new GroupOperator();
            criteria.Operands.Add(new BinaryOperator("Top", "否", BinaryOperatorType.Equal));
            criteria.Operands.Add(new BinaryOperator("Important", "否", BinaryOperatorType.Equal));
            userOperation = new XpoHelper.Test<Mtb_VideoInformationArticle>();
            return userOperation.Operation(criteria);
        }

        /// <summary>
        /// 根据公告Id查询并返回视频资讯单一记录
        /// </summary>
        /// <param name="id">需要查询的视频资讯Id</param>
        /// <returns>返回公告单一记录</returns>
        public Mtb_VideoInformationArticle SelectVideoInformationArticleById(int id)
        {
            Mtb_VideoInformationArticle bulletin = null;
            userOperation = new XpoHelper.Test<Mtb_VideoInformationArticle>();
            XPCollection xp = userOperation.Operation("OID", id);
            foreach (Mtb_VideoInformationArticle b in xp)
            {
                bulletin = b;
            }
            return bulletin;
        }

        /// <summary>
        /// 显示置顶视频资讯
        /// </summary>
        /// <returns>返回置顶视频资讯列表</returns>
        public XPCollection SelectVideoInformationArticleByTop()
        {
            userOperation = new XpoHelper.Test<Mtb_VideoInformationArticle>();
            XPCollection xp = userOperation.Operation("Top","是");
            //按照发布时间进行降序排列
            SortProperty sp = new SortProperty("PublishDate", DevExpress.Xpo.DB.SortingDirection.Descending);
            xp.Sorting.Add(sp);
            return xp;
        }

        /// <summary>
        /// 显示重点视频资讯
        /// </summary>
        /// <returns>返回重点视频资讯列表</returns>
        public XPCollection SelectVideoInformationArticleByImportant()
        {
            userOperation = new XpoHelper.Test<Mtb_VideoInformationArticle>();
            XPCollection xp = userOperation.Operation("Important","是");
            //按照发布时间进行降序排列
            SortProperty sp = new SortProperty("PublishDate", DevExpress.Xpo.DB.SortingDirection.Descending);
            xp.Sorting.Add(sp);
            return xp;
        }

        /// <summary>
        /// 显示首页的视频资讯内容
        /// </summary>
        /// <returns></returns>
        public XPCollection SelectVideoInformationArticleByTopAndImportant()
        {
            XPCollection xp = new XPCollection(typeof(Mtb_VideoInformationArticle));
            xp.AddRange(SelectVideoInformationArticleByTop());
            xp.AddRange(SelectVideoInformationArticleByImportant());
            xp.AddRange(SelectAllVideoInformationArticle());
            return xp;
        }

        /// <summary>
        /// 设置公告为重点显示
        /// </summary>
        /// <returns>1：更新成功  0：更新失败</returns>
        public int UpdateBulletinArticleByImportant(Mtb_VideoInformationArticle bulletin)
        {
            userOperation = new XpoHelper.Test<Mtb_VideoInformationArticle>();
            XPCollection xp = userOperation.Operation("OID", bulletin.OID);
            foreach (Mtb_VideoInformationArticle b in xp)
            {
                b.Important = bulletin.Important;
                return XpoHelper.SaveModified(b);
            }
            return 0;
        }

        /// <summary>
        /// 设置公告为置顶显示
        /// </summary>
        /// <returns>1：更新成功  0：更新失败</returns>
        public int UpdateBulletinArticleByTop(Mtb_VideoInformationArticle bulletin)
        {
            userOperation = new XpoHelper.Test<Mtb_VideoInformationArticle>();
            XPCollection xp = userOperation.Operation("OID", bulletin.OID);
            foreach (Mtb_VideoInformationArticle b in xp)
            {
                b.Top = bulletin.Top;
                return XpoHelper.SaveModified(b);
            }
            return 0;
        }
    }
}
